<?php

namespace app\admin\model\project;

use think\Model;


class ProjectApply extends Model
{

    

    

    // 表名
    protected $name = 'project_apply';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [

    ];

    public function getWorkWeek($week)
    {
        $work_day_arr = explode(',',$week);

        usort($work_day_arr, function($a, $b) {
            return $a - $b; // 升序
        });

        $star = $this->getWeek()[$work_day_arr[0]];
        $end = $this->getWeek()[end($work_day_arr)];

        return $star.'到'.$end;
    }


    //转换店铺的营业日期
    /*public function getWorkWeek($week)
    {
        $week = explode(',',$week);
        $week_list = [0,1,2,3,4,5,6];

        $res = $this->hasDuplicates($week,$week_list);
        $week_list = $this->getWeek();
        if ($res){

            $work_week = [];
            foreach ($week as $k=>$v){
                array_push($work_week,$week_list[$v]);
            }
            return $work_week;
        } else {
            return '周一至周日';
        }
    }*/

    public function hasDuplicates($array1, $array2) {
        $diff = array_diff(array_merge($array1, $array2), array_intersect($array1, $array2));
        return !empty($diff);
    }

    public function getWeek()
    {
        return [1=>'周一',2=>'周二',3=>'周三',4=>'周四',5=>'周五',6=>'周六',7=>'周日'];
    }






}
